<?php
require_once ('../lib/config.php');
require_once ('../lib/facebook.php');
require_once ('../lib/friends.php');
require_once ('../lib/friend.php');
require_once ('../lib/test.php');
require_once ('../../simpletest/autorun.php');
require_once ('../lib/init.php');
require_once ('../data_sample/mockup_data_comment.php');

class TestFunc_processMyCommentOnNote extends UnitTestCase {
    
    function setUp(){
        global $login_button,$facebook;
        
        if(isLoggedIn()){
            try{
                $me = getOneself();
            }catch(Exception $e){
                print($login_button);
                exit();
            }
        }
    }
    
//Case3: I wrote a comment on a note of one of friends (regardless of where it is)
    function test_case3(){
        global $commentCase3;
        $data = $commentCase3;
        $friends = array();
        
        processMyCommentOnNote($friends, $data);
        
        $this->assertNotNull($friends);
        $this->assertTrue(is_array($friends));
        $this->assertFalse(empty($friends));
        
        $this->assertEqual(count($friends), 1);
        
        $isExistIDs =isset($friends['100000416787478']);
        $this->assertTrue($isExistIDs);
        if($isExistIDs){
            $friend = $friends['100000416787478'];
            $this->assertEqual($friend->getNumberOfData("MY_COMMENT_ON_NOTE_FLAG"), 1);

        }    
    }
//    3.1: I wrote comments on notes of one of friends (regardless of where it is)
    function test_case31(){
        global $commentCase31;
        $data = $commentCase31;
        $friends = array();
        
        processMyCommentOnNote($friends, $data);
        
        $this->assertNotNull($friends);
        $this->assertTrue(is_array($friends));
        $this->assertFalse(empty($friends));
        
        $this->assertEqual(count($friends), 1);
        
        $isExistIDs =isset($friends['100000416787478']);
        $this->assertTrue($isExistIDs);
        if($isExistIDs){
            $friend = $friends['100000416787478'];
            $this->assertEqual($friend->getNumberOfData("MY_COMMENT_ON_NOTE_FLAG"), 2);
        }         
    }
//    3.2: I wrote a comment on each note of two friends (regardless of where it is)
    function test_case32(){
        global $commentCase32;
        $data = $commentCase32;
        $friends = array();
        
        processMyCommentOnNote($friends, $data);
        
        $this->assertNotNull($friends);
        $this->assertTrue(is_array($friends));
        $this->assertFalse(empty($friends));
        
        $this->assertEqual(count($friends), 2);
        
        $isExistIDs =isset($friends['100000416787478']) && isset($friends['100000525262538']);
        $this->assertTrue($isExistIDs);
        if($isExistIDs){
            $friend = $friends['100000416787478'];
            $this->assertEqual($friend->getNumberOfData("MY_COMMENT_ON_NOTE_FLAG"), 1);
            $friend = $friends['100000525262538'];
            $this->assertEqual($friend->getNumberOfData("MY_COMMENT_ON_NOTE_FLAG"), 1);
        } 
        
    }
//    3.3: I wrote comments on links of two friends (regardless of where it is)
    function test_case33(){
        global $commentCase33;
        $data = $commentCase33;
        $friends = array();
        
        processMyCommentOnNote($friends, $data);
        
        $this->assertNotNull($friends);
        $this->assertTrue(is_array($friends));
        $this->assertFalse(empty($friends));
        
        $this->assertEqual(count($friends), 2);
        
        $isExistIDs =isset($friends['100000416787478']) && isset($friends['100000525262538']);
        $this->assertTrue($isExistIDs);
        if($isExistIDs){
            $friend = $friends['100000416787478'];
            $this->assertEqual($friend->getNumberOfData("MY_COMMENT_ON_NOTE_FLAG"), 3);
            $friend = $friends['100000525262538'];
            $this->assertEqual($friend->getNumberOfData("MY_COMMENT_ON_NOTE_FLAG"), 2);
        }         
    }
    //refer to http://www.simpletest.org/en/unit_test_documentation.html
    function test_processMyCommentOnNote(){ 
        $friends = array();
        $data = getMyCommentOnNote();
        
        processMyCommentOnNote($friends, $data);
        
        $this->assertNotNull($friends);
        $this->assertTrue(is_array($friends));
        $this->assertFalse(empty($friends));
    }
    
}
?>
